<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="../list/index.html">&lt; 8. All purposes container</a>
</td><td width="60%">
<p align="center">
=====================================<br />
9. Pseudorandom number generator<br />
=====================================<br />
</p></td><td width="20%">
<a href="../noise/index.html">&gt; 10. Noise generator</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
This toolkit is an implementation of two fast and high quality pseudorandom number generators:
<ul><li>a <a href="http://en.wikipedia.org/wiki/Mersenne_Twister">Mersenne twister</a> generator</li>
<li>a <a href="http://en.wikipedia.org/wiki/Multiply-with-carry#Complementary-multiply-with-carry_generators">Complementary-Multiply-With-Carry</a> generator,</li></ul>
<p>CMWC is faster than MT (see table below) and has a much better period (10<sup>39460</sup> vs. 10<sup>6001</sup>). It is the default algo since libtcod 1.5.0.<br />
Relative performances in two independent tests:</p>
<table class="none">
<tr><th>Algorithm</th><th>Numbers generated</th><th>Perf (1)</th><th>Perf (2)</th></tr>
<tr bgcolor="#EEEEEE"><td>MT</td><td>integer</td><td>62</td><td>50</td></tr>
<tr><td>MT</td><td>float</td><td>54</td><td>45</td></tr>
<tr bgcolor="#EEEEEE"><td>CMWC</td><td>integer</td><td>21</td><td>34</td></tr>
<tr><td>CMWC</td><td>float</td><td>32</td><td>27</td></tr>
</table>
<p>For python users :<br />
Python already has great builtin random generators. But some parts of the Doryen library (noise, heightmap, ...) uses RNG as parameters. If you intend to use those functions, you must provide a RNG created with the library.</p>
<p>
<a href="random_init.html">9.1 Creating a generator</a><br />
<a href="random_use.html">9.2 Using a generator</a><br />
<a href="random_delete.html">9.3 Destroying a generator</a></p>
